package aimozg.utils;

import java.util.LinkedList;
import java.util.List;

public class ListsArray<E>{

	protected LinkedList<E>[] array;
	protected int length;
	
	@SuppressWarnings("unchecked")
	public ListsArray(int length){
		this.length = length;
		array = new LinkedList[length];
	}
	
	protected void check(int i) throws ArrayIndexOutOfBoundsException{
		if (i<0 || i>=length) throw new ArrayIndexOutOfBoundsException(i);
		if (array[i] == null) array[i] = new LinkedList<E>();
	}
	
	public List<E> at(int i) throws ArrayIndexOutOfBoundsException{
		check(i);
		return array[i];
	}
	
	public boolean put(int i, E element){
		check(i);
		return array[i].add(element);
	}
	
	public boolean remove(int i, E element){
		check(i);
		return array[i].remove(element);
	}

}
